package thread1;

public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread() {
            @Override
            public void run() {
                while (!this.isInterrupted()) {
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
//                        break;
                    }
                }
            }
        };
        thread.start();

        Thread.sleep(5000);

        thread.interrupt();
    }
}
